%%
clear
scale = 3;
% solver_mode = 'gpu 0';

%%
Sets = {'Set5', 'Set14', 'Urban100'}; %, 'B100', 'General100'};
% Sets = {'Set5'};
Models = {'FSRCNN', 'RED', 'DRRN'}; %, 'SRCNN', 'VDSR', 
flag   = [0, 0, 1];
ImgIdx = {
    3 3 5
    11 11 8
    43 93 44
    };
Versions = {scale, scale, scale};

load(fullfile('E:\Academic\X\!SR\2017-01-15-ResSR\code\srcaffe\Models', 'Images.mat'));

close all
for mi = 1 : length(Models)
    if flag(mi) == 0, continue; end
    figure;
    for si = 1 : length(Sets)
        imList = Imgs.(Models{mi}).(Sets{si});
        psnrs = PSNRs.(Models{mi}).(Sets{si});
        
        ImgPairs = srimg.genLHPairs(Sets{si}, scale, ImgIdx{si, mi}, 'ycbcr');
        
        if strcmpi(Models{mi}, 'FSRCNN')
            ImgPairs = ImgPairs(:, [1, 3]);
            ImgPairs{2} = srimg.shave(ImgPairs{2}, [1 1]);
            imList{end} = srimg.shave(imList{end}, [1 1]);
        else
            ImgPairs = ImgPairs(:, 2 : 3);
        end
        
        %%
        for i = 1 : length(imList)
            if i == 1
                k = 1; ImgPairs{1}(:, :, 1) = imList{i};
            else
                k = 2; ImgPairs{2}(:, :, 1) = imList{i};
            end
            imList{i} = ImgPairs{k};
        end
        
        subplot(length(Sets), 1, si);
        himg = imshow(ycbcr2rgb(imList{end}));
        set(himg, 'ButtonDownFcn', @(hObject, eventdata) srimg.compare_results(Models{mi}, scale, imList{[end, 1 : 3]}));
        
%         for i = 1 : length(imList)
%             if i == 1
%                 k = 1; ImgPairs{1}(:, :, 1) = imList{i};
%             else
%                 k = 2; ImgPairs{2}(:, :, 1) = imList{i};
%             end
%             img1 = ImgPairs{k};
%             subplot(1,4,i);  himg = imshow(ycbcr2rgb(img1));
%             
%             img2 = []; img3 = [];
%             if i == 2
%                 ImgPairs{2}(:, :, 1) = imList{i+1};
%                 img2 = ImgPairs{2};
%                 ImgPairs{2}(:, :, 1) = imList{end};
%                 img3 = ImgPairs{2};
%                 title(sprintf('%.3f', psnrs(1)));
%             elseif i == 3
%                 ImgPairs{2}(:, :, 1) = imList{i-1};
%                 img2 = ImgPairs{2};
%                 ImgPairs{2}(:, :, 1) = imList{end};
%                 img3 = ImgPairs{2};
%                 title(sprintf('%.3f', psnrs(2)));
%             end
%             set(himg, 'ButtonDownFcn', @(hObject, eventdata) newimshow(img1, img2, img3));
%         end
    end
end
